<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.name" placeholder="请输入名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="12">
            <a-form-model-item label="项目" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="equipmentId">
              <j-dict-select-tag type="list" v-model="model.equipmentId" dictCode="yks_equipment,name,id" placeholder="请选择项目" />
            </a-form-model-item>
          </a-col> -->
          <a-col :span="12">
            <a-form-model-item label="运维类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="devopsPersontype">
              <j-dict-select-tag type="list" :disabled="true"  v-model="model.devopsPersontype" dictCode="devops_persontype" placeholder="请选择运维类型" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="运维人员" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="maintenancePerson">
              <j-dict-select-tag type="list" v-model="model.maintenancePerson" dictCode="sys_user,username,id" placeholder="请选择运维人员" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="运维部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="maintenanceDept">
              <j-dict-select-tag type="list" v-model="model.maintenanceDept" dictCode="sys_depart,depart_name,id" placeholder="请选择运维部门" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="触发类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="triggerType">
              <j-dict-select-tag type="list" v-model="model.triggerType" dictCode="trigger_type" placeholder="请选择触发类型" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="初次触发时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="triggerTime">
              <j-date placeholder="请选择初次触发时间" v-model="model.triggerTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="重复次数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="repeatNumber">
              <a-input v-model="model.repeatNumber" placeholder="请输入重复次数"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="重复间隔" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="repeatGap">
              <a-input v-model="model.repeatGap" placeholder="请输入重复间隔"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="重复间隔单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="repeatGapUnit">
              <j-dict-select-tag type="list" v-model="model.repeatGapUnit" dictCode="yks_unit,name,id" placeholder="请选择重复间隔单位" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="下次计划保养时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="maintenanceNextTime">
              <j-date placeholder="请选择下次计划保养时间" v-model="model.maintenanceNextTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="保养时间段开始" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="maintenanceQuantumstart">
              <j-date placeholder="请选择保养时间段开始" v-model="model.maintenanceQuantumstart"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="保养时间段结束" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="maintenanceQuantumend">
              <j-date placeholder="请选择保养时间段结束" v-model="model.maintenanceQuantumend"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="保养类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="maintenanceType">
              <j-dict-select-tag type="list" v-model="model.maintenanceType" dictCode="maintenance_type" placeholder="请选择保养类型" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="保养内容" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="maintenanceContext">
              <a-input v-model="model.maintenanceContext" placeholder="请输入保养内容"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="模块" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="templateId" forceRender>
              <j-multi-select-tag type="list_multi" v-model="model.templateId" :dictCode="templateDict" placeholder="请选择模版ID" forceRender/>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="12">
            <a-form-model-item label="化学药剂" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productId">
              <j-multi-select-tag type="list_multi" v-model="model.productId" :dictCode="productDict" placeholder="请选择本次需要运维的化学药剂" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="运维材料" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="templateId">
              <j-multi-select-tag type="list_multi" v-model="model.materialId" :dictCode="materialDict" placeholder="请选择本次需要运维的运维材料" />
            </a-form-model-item>
          </a-col> -->
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'YksEquipmentDevopsForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        currentEquipmentId:'',
        confirmLoading: false,
        validatorRules: {
           name: [
              { required: true, message: '请输入名称!'},
           ],
          //  equipmentId: [
          //     { required: true, message: '请输入项目!'},
          //  ],
           devopsPersontype: [
              { required: true, message: '请输入运维类型!'},
           ],
        },
        url: {
          add: "/dev/yksEquipmentDevops/add",
          edit: "/dev/yksEquipmentDevops/edit",
          queryById: "/dev/yksEquipmentDevops/queryById"
        },
        serviceType:'',
        DevopsItems:[],
        templateDict:'yks_maintenance_template,template_name,id,del_flag=0',//
        productDict:'dev_equipment_config_product,product_name,id,del_flag=0',
        materialDict:'yks_equipment_configuration_part,material_name,id,del_flag=0'
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    watched:{
      templateDict:{
        immediate:true,
        handler() {
          if(this.model.equipmentId){
            this.templateDict="yks_maintenance_template,template_name,id,del_flag=0 and equipment_id="+this.model.equipmentId
          }
         
        },
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
      
    },
    mounted(){
      if(this.model.equipmentId){
        this.templateDict="yks_maintenance_template,template_name,id,del_flag=0 and equipment_id="+this.model.equipmentId
      }
      
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.model.equipmentId = this.currentEquipmentId
        this.templateDict="yks_maintenance_template,template_name,id,del_flag=0 and equipment_id="+this.model.equipmentId
        // this.productDict=this.productDict+",del_flag=0&&equipment_id="+this.model.equipmentId
        // this.materialDict=this.materialDict+",del_flag=0&&equipment_id="+this.model.equipmentId
        this.model.devopsPersontype=this.serviceType
        this.visible = true;
      },
      submitForm () {
        
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>